﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using Aandelendelen.Db;
using Aandelendelen.Mail;
using NLog;

namespace Aandelendelen.Daily
{
	public abstract class DailyJob
	{
		private static Logger logger = LogManager.GetCurrentClassLogger();

		string logMessage = "";
		protected QueryCollection queries = new QueryCollection();
		protected BulkEMail emails = new BulkEMail();
		protected XmlNode jobNode;

		public DailyJob(XmlNode jobNode)
		{
			this.jobNode = jobNode;
		}

		public DailyJob(XmlNode jobNode, string logMessage)
			: this(jobNode)
		{
			this.logMessage = logMessage;
		}

		protected void OnStart()
		{
			logger.Info(this.logMessage);
		}

		protected void OnEnd()
		{
			logger.Info("Done.");
		}

		protected void OnError(Exception e)
		{
			logger.InfoException("Daily job error ", e);
		}

		public QueryCollection Queries
		{
			get { return this.queries; }
		}

		public BulkEMail Emails
		{
			get { return this.emails; }
		}

		public abstract void Execute();

	}
}